package com.xiaoxin.common.dto;

import com.alibaba.fastjson.JSONObject;
import com.xiaoxin.common.ResponseStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @version v1.0
 * @Description: 封装返回值
 * @Author: TongRui乀
 * @Date: 2021/11/23 3:46 下午
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class ResponseBody {

    private static JSONObject EMPTY = new JSONObject();

    private Integer code;

    private String msg;

    private Object data;

    private PageResult page;

    public static ResponseBody ok(){
        var res = new ResponseBody();
        res.code = ResponseStatus.OK.code();
        res.msg = ResponseStatus.OK.msg();
        return res;
    }

    public static ResponseBody ok(Object data){
        var res = new ResponseBody();
        res.code = ResponseStatus.OK.code();
        res.msg = ResponseStatus.OK.msg();
        res.data = data;
        return res;
    }

    public static ResponseBody system_error(){
        var res = new ResponseBody();
        res.code = ResponseStatus.SYSTEM_ERROR.code();
        res.msg = ResponseStatus.SYSTEM_ERROR.msg();
        return res;
    }
}
